package com.cn.ycy.quartz;

import org.quartz.*;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

//  @Bean
  public JobDetail JobDetail1() {
    return JobBuilder.newJob(TestTask1.class).withIdentity("testTask1").storeDurably().build();
  }

//  @Bean
  public Trigger testQuartzTrigger1() {
    //5秒执行一次
    SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
            .withIntervalInSeconds(5)
            .repeatForever();

    return TriggerBuilder.newTrigger().forJob(JobDetail1())
            .withIdentity("testTask1")
            .withSchedule(scheduleBuilder)
            .build();
  }

//  @Bean
  public JobDetail JobDetail2() {
    return JobBuilder.newJob(TestTask2.class).withIdentity("testTask2").storeDurably().build();
  }

//  @Bean
  public Trigger testQuartzTrigger2() {
    //cron方式，每隔5秒执行一次
    CronTrigger crontrigger = TriggerBuilder.newTrigger().forJob(JobDetail2())
            .withIdentity("testTask2")
            .withSchedule(CronScheduleBuilder.cronSchedule("*/5 * * * * ?"))
            .build();
    return crontrigger;
  }


}
